import Vue from 'vue'
import App from './App.vue'
import router from './router'
import  './plugins/element.js'
import "./assets/css/global.css"
import has  from './permission.js'
import axios from "axios"


Vue.config.productionTip = false

axios.defaults.baseURL='http://localhost:80'
axios.interceptors.request.use(config=>{
  config.headers.token=window.sessionStorage.getItem("token")
  return config;
})
axios.interceptors.response.use(
  response => {
    //当返回信息为未登录或者登录失效的时候重定向为登录页面
    if (response.data.code == 20002 || response.data.message == '用户未登录或登录超时，请登录！') {
      router.push({
        path: "/",
        querry: { redirect: router.currentRoute.fullPath }//从哪个页面跳转
      })
    }
    if (response.data.code == 20003 || response.data.message == '用户没有该权限！') {
      router.push({
        path: "/unauth",
        
      })
    }
    return response;
  },
  error => {
    return Promise.reject(error)
  }
)
// 把axios绑定到$http上
Vue.prototype.$http=axios

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
